package cn.com.utt.common.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import cn.com.utt.common.vo.Resource;

public interface ResourceMapper {
	
	@Select("select re.* from ${resourceTableName} re,role ro,${roleResourceTableName} rr where rr.resource_id=re.id and rr.role_id=ro.id and re.pid=0 and ro.id in(select r.id from role r,user u,user_role ur where r.id = ur.rid and u.id=ur.uid and u.id=#{userId} and (r.rw=0 or r.type=2)) order by `order` asc")
	List<Resource> queryFirstMenu(@Param("userId")Long userId,@Param("resourceTableName")String resourceTableName,@Param("roleResourceTableName")String roleResourceTableName);
	
	@Select("select re.* from ${resourceTableName} re,role ro,${roleResourceTableName} rr where rr.resource_id=re.id and rr.role_id=ro.id and re.pid!=0 and pid=#{res.id} and ro.id in(select r.id from role r,user u,user_role ur where r.id = ur.rid and u.id=ur.uid and u.id=#{userId} and (r.rw=0 or r.type=2)) order by `order` asc")
	List<Resource> querySecondMenu(@Param("userId")Long userId,@Param("res")Resource res,@Param("resourceTableName")String resourceTableName,@Param("roleResourceTableName")String roleResourceTableName);
	
}
